package com.ytc.company.controller;

import com.ytc.company.model.Company;
import com.ytc.company.service.CompanyService;
import com.ytc.data.model.Data;
import com.ytc.data.service.DataService;
import com.ytc.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//公司
@Controller
@RequestMapping("company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @Autowired
    private DataService dataService;

    //新增
    @RequestMapping("/addCompany")
    @ResponseBody
    public void addCompany(Company company,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        company.setUserId(user.getUserId());
        companyService.addCompany(company);
    }

    //修改
    @RequestMapping("/updateCompany")
    @ResponseBody
    public void updateCompany(Company company){
        companyService.updateCompany(company);
    }

    //查询
    @RequestMapping("/getCompany")
    @ResponseBody
    public Company getCompany(HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        return companyService.getCompany(user.getUserId());
    }

    //初始页面
    @RequestMapping("toCompany")
    public String toAddPosition(Model model,HttpServletRequest request){

        List<Data> companyType = dataService.getData("公司类型");
        List<Data> companySize = dataService.getData("公司规模");
        List<Data> financingPhase = dataService.getData("融资阶段");

        User user =(User) request.getSession().getAttribute("user");
        Company company = companyService.getCompany(user.getUserId());

        model.addAttribute("companyType",companyType);
        model.addAttribute("companySize",companySize);
        model.addAttribute("financingPhase",financingPhase);
        //model.addAttribute("company",company);

        return "company/company";
    }


    //初始页面
    @RequestMapping("toCompany1")
    public String toAddPosition1(Model model,HttpServletRequest request){

        List<Data> companyType = dataService.getData("公司类型");
        List<Data> companySize = dataService.getData("公司规模");
        List<Data> financingPhase = dataService.getData("融资阶段");

        User user =(User) request.getSession().getAttribute("user");
        Company company = companyService.getCompany(user.getUserId());

        model.addAttribute("companyType",companyType);
        model.addAttribute("companySize",companySize);
        model.addAttribute("financingPhase",financingPhase);
        model.addAttribute("company",company);

        return "company/showCompany";
    }


}
